{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if The Number is Fascinating"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isFascinating"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断一个数是否迷人"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个三位数整数 <code>n</code>&nbsp;。</p>\n",
    "\n",
    "<p>如果经过以下修改得到的数字 <strong>恰好</strong>&nbsp;包含数字 <code>1</code>&nbsp;到 <code>9</code>&nbsp;各一次且不包含任何 <code>0</code>&nbsp;，那么我们称数字 <code>n</code>&nbsp;是 <strong>迷人的</strong>&nbsp;：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>将&nbsp;<code>n</code>&nbsp;与数字&nbsp;<code>2 * n</code> 和&nbsp;<code>3 * n</code>&nbsp;<strong>连接</strong>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p>如果 <code>n</code>&nbsp;是迷人的，返回&nbsp;<code>true</code>，否则返回&nbsp;<code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p><strong>连接</strong>&nbsp;两个数字表示把它们首尾相接连在一起。比方说&nbsp;<code>121</code> 和&nbsp;<code>371</code>&nbsp;连接得到&nbsp;<code>121371</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>n = 192\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>我们将数字 n = 192 ，2 * n = 384 和 3 * n = 576 连接，得到 192384576 。这个数字包含 1 到 9 恰好各一次。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>n = 100\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>我们将数字 n = 100 ，2 * n = 200 和 3 * n = 300 连接，得到 100200300 。这个数字不符合上述条件。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>100 &lt;= n &lt;= 999</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-the-number-is-fascinating](https://leetcode.cn/problems/check-if-the-number-is-fascinating/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-the-number-is-fascinating](https://leetcode.cn/problems/check-if-the-number-is-fascinating/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['192', '100']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int)-> bool:\n",
    "        if n > 333:\n",
    "            return False\n",
    "        mask = 0\n",
    "        for c in str(n) + str(2 * n) + str(3 * n):\n",
    "            mask |= 1 << int(c)\n",
    "        return mask == (1 << 10 ) - 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "      return n in [192,219,273,327]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        save = set()\n",
    "        for i in s:\n",
    "            if i == '0' or i in save:\n",
    "                return False\n",
    "            save.add(i)\n",
    "        return len(save) == 9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n < 123 or n > 329:\n",
    "            return False\n",
    "        s = str(n) + str(n * 2) + str(n* 3)\n",
    "        return '0' not in s and len(set(s)) == 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return sorted(list(''.join(str(n*i) for i in (1,2,3)))) == [str(i) for i in range(1,10)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        cur = str(n) + str(n*2) + str(n*3)\n",
    "        return Counter(cur) == Counter(\"123456789\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in (192, 219, 273, 327)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return ''.join(sorted(str(n) + str(n << 1) + str(n * 3))) == ''.join(map(str, list(range(1, 10))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        vis = [False] * 10\n",
    "        for ch in str(n)+str(2*n)+str(3*n):\n",
    "            num = int(ch)\n",
    "            if not num or vis[num]:\n",
    "                return False\n",
    "            vis[num] = True\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False\n",
    "        else:\n",
    "            s = str(n) + str(2*n) + str(3*n)\n",
    "            l = [0 for i in range(0, 9)]\n",
    "            for i in s:\n",
    "                if i == '0':\n",
    "                    return False\n",
    "                else:\n",
    "                    l[int(i)-1] += 1\n",
    "            else:\n",
    "                if l == [1,1,1,1,1,1,1,1,1]:\n",
    "                    return True\n",
    "                else:\n",
    "                    return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in (192, 219, 273, 327)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        str_num = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in str_num:\n",
    "            return False\n",
    "\n",
    "        return len(str_num) == 9 and len(''.join(set(list(str_num)))) == 9\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        last={}\n",
    "        cur,count=n,1\n",
    "        while cur:\n",
    "            ans=cur%10\n",
    "            if ans in last or ans==0:\n",
    "                return False\n",
    "            else:\n",
    "                last[ans]=1\n",
    "            cur//=10\n",
    "            if cur==0 and count<3:\n",
    "                count+=1\n",
    "                cur=n*count\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        v = list(s)\n",
    "        l = set(v)\n",
    "        if \"0\" not in l and len(l) == 9 and len(v) == 9:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return sorted(list(''.join(str(n*i) for i in (1,2,3)))) == [str(i) for i in range(1,10)]\n",
    "        # return n in (192,219,273,327)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        st=str(n)\n",
    "        st+=str(2*n)\n",
    "        st+=str(3*n)\n",
    "        return set(st)==set('123456789') and len(st)==9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:return False\n",
    "        temp = str(n) + str(2*n) + str(3*n)\n",
    "        a = set()\n",
    "        for i in temp:\n",
    "            if i in a or i == '0':\n",
    "                return False\n",
    "            else:\n",
    "                a.add(i)\n",
    "        \n",
    "        return True if len(a) == 9 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        hash_s =set()\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in s:\n",
    "            return False\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        is_in = [0 for _ in range(10)]\n",
    "        for ch in s:\n",
    "            if ch == \"0\":\n",
    "                return False\n",
    "            is_in[int(ch)] += 1\n",
    "        for i in range(1,10):\n",
    "            if is_in[i] != 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return len(s) == len(set(s)) == 9 and '0' not in s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False    \n",
    "        lst = [192, 219, 273, 327]\n",
    "        return n in lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        cnt = [0] * 10\n",
    "        cnt[0] = 1\n",
    "\n",
    "        x = n\n",
    "        while x > 0:\n",
    "            x, r = divmod(x, 10)\n",
    "            if cnt[r] >= 1:\n",
    "                return False\n",
    "            cnt[r] += 1\n",
    "        \n",
    "        x = 2 * n\n",
    "        while x > 0:\n",
    "            x, r = divmod(x, 10)\n",
    "            if cnt[r] >= 1:\n",
    "                return False\n",
    "            \n",
    "            cnt[r] += 1\n",
    "\n",
    "        x = 3 * n\n",
    "        while x > 0:\n",
    "            x, r = divmod(x, 10)\n",
    "            if cnt[r] >= 1:\n",
    "                return False\n",
    "            \n",
    "            cnt[r] += 1\n",
    "\n",
    "        return sum(cnt[1:]) == 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return ''.join(sorted(str(n) + str(2 * n) + str(3 * n))) == \"123456789\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        num = str(n) + str(2*n) + str(3*n)\n",
    "        f = [0] * 10\n",
    "        for c in num:\n",
    "            f[ord(c) - ord('0')] += 1\n",
    "        if f[0] > 0:\n",
    "            return False\n",
    "        for i in range(1, 10):\n",
    "            if f[i] != 1:\n",
    "                return False\n",
    "            \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n < 123 or n > 329:\n",
    "            return False\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return '0' not in s and len(set(s)) == 9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False\n",
    "        else:\n",
    "            s = str(n) + str(2*n) + str(3*n)\n",
    "            l = [0 for i in range(0, 9)]\n",
    "            for i in s:\n",
    "                if i == '0':\n",
    "                    return False\n",
    "                    break\n",
    "                else:\n",
    "                    l[int(i)-1] += 1\n",
    "            else:\n",
    "                if l == [1,1,1,1,1,1,1,1,1]:\n",
    "                    return True\n",
    "                else:\n",
    "                    return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return len(s) == 9 and len(set(s)) == 9 and '0' not in s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        d={}\n",
    "        for x in str(n):\n",
    "            if x == \"0\":\n",
    "                return False\n",
    "            d[x]=d.get(x,0)+1\n",
    "            if d[x] > 1:\n",
    "                return False\n",
    "        for x in str(2*n):\n",
    "            if x == \"0\":\n",
    "                return False\n",
    "            d[x] = d.get(x,0)+1\n",
    "            if d[x] > 1:\n",
    "                return False \n",
    "        for x in str(3*n):\n",
    "            if x == \"0\":\n",
    "                return False\n",
    "            d[x] = d.get(x,0)+1\n",
    "            if d[x] > 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        hash_s =set()\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in s:\n",
    "            return False\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        OnetNineSet = set()\n",
    "        num = n\n",
    "        while num != 0:\n",
    "            if num%10 in OnetNineSet:\n",
    "                return False\n",
    "            else:\n",
    "                OnetNineSet.add(num%10)\n",
    "            num = num // 10\n",
    "        num = 2*n\n",
    "        while num != 0:\n",
    "            if num%10 in OnetNineSet:\n",
    "                return False\n",
    "            else:\n",
    "                OnetNineSet.add(num%10)\n",
    "            num = num // 10\n",
    "\n",
    "        num = 3*n\n",
    "        while num != 0:\n",
    "            if num%10 in OnetNineSet:\n",
    "                return False\n",
    "            else:\n",
    "                OnetNineSet.add(num%10)\n",
    "            num = num // 10\n",
    "\n",
    "        if len(OnetNineSet) == 9 and 0 not in OnetNineSet:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        num = \"\".join([str(n), str(2*n), str(3*n)])\n",
    "        if len(num) != 9:\n",
    "            return False\n",
    "        for i in range(1, 10):\n",
    "            if str(i) not in num:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in (192, 219, 273, 327)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in {192, 219, 273, 327}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False\n",
    "        else:\n",
    "            s = str(n) + str(2*n) + str(3*n)\n",
    "            l = [0 for i in range(0, 9)]\n",
    "            for i in s:\n",
    "                if i == '0':\n",
    "                    return False\n",
    "                else:\n",
    "                    l[int(i)-1] += 1\n",
    "            if l == [1,1,1,1,1,1,1,1,1]:\n",
    "                return True\n",
    "            else:\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        x = str(n) + str(2*n) + str(3*n)\n",
    "        x = str(x)\n",
    "        \n",
    "        cnt = [0] * 10\n",
    "        for ch in x:\n",
    "            cnt[int(ch)] += 1\n",
    "        \n",
    "        if cnt[0] > 0:\n",
    "            return False\n",
    "        else:\n",
    "            for c in cnt[1:]:\n",
    "                if c != 1:\n",
    "                    return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n < 123 or n > 329:\n",
    "            return False\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return '0' not in s and len(set(s)) == 9\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n)+str(2*n)+str(3*n)\n",
    "        counter = Counter(s)\n",
    "        for key, val in counter.items():\n",
    "            if key == '0' or val > 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def isFascinating(self, n):\n",
    "        a = 0\n",
    "        if sum([(str(n) + str(n * 2) + str(n * 3)).count(str(i)) == 1 for i in range(1, 10)]) == 9:\n",
    "            a = 1\n",
    "        return a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False    \n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return set(s) == set(\"123456789\") if len(s) == 9 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        n2=2*n\n",
    "        n3=3*n\n",
    "        str_mr=str(n)+str(n2)+str(n3)\n",
    "        if '0' not in str_mr and len(set(list(str_mr)))==9 and len(str_mr)==9:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return set(s) == set(\"123456789\") if len(s) == 9 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        charset = set()\n",
    "        for char in s:\n",
    "            charset.add(char)\n",
    "        if len(s) == 9 and len(charset) == 9 and '0' not in charset:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        hash_s =set()\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in s:\n",
    "            return False\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        num1=n\n",
    "        num2=2*n\n",
    "        num3=3*n\n",
    "        num=str(num1)+str(num2)+str(num3)\n",
    "        for i in range(len(num)):\n",
    "            if num.count(num[i])!=1:\n",
    "                return False\n",
    "        if num.count('0'):\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n < 123 or n > 329:\n",
    "            return False\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return '0' not in s and len(set(s)) == 9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n == 192 or n == 219 or n == 273 or n == 327"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in [192, 219, 273, 327]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        hash_s =set()\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in s:\n",
    "            return False\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def isFascinating(self, n):\n",
    "        if sum([(str(n) + str(n * 2) + str(n * 3)).count(str(i)) == 1 for i in range(1, 10)]) == 9:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        x1=n*2\n",
    "        x2=n*3\n",
    "        s=str(n)+str(x1)+str(x2)\n",
    "        flag = 0    \n",
    "        if len(set(s)) !=len(s): #有重复的值，直接退出\n",
    "            flag =1\n",
    "        else:\n",
    "            for i in s:\n",
    "                if i == '0':\n",
    "                    flag = 1\n",
    "                    break\n",
    "        return flag==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False    \n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return set(s) == set(\"123456789\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n > 333:\n",
    "            return False\n",
    "        num_str = str(n) + str(n*2) + str(n*3)\n",
    "        num_set = set()\n",
    "        for i in range(len(num_str)):\n",
    "            num_set.add(num_str[i])\n",
    "        if '0' in num_set:\n",
    "            return False\n",
    "        if len(num_set) == len(num_str):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in (192, 219, 273, 327)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        if n < 123 or n > 329:\n",
    "            return False\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        return '0' not in s and len(set(s)) == 9\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in [192, 219, 273, 327]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        hash_s =set()\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        if '0' in s:\n",
    "            return False\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s=str(n)+str(n*2)+str(n*3)\n",
    "        if len(s)!=9:\n",
    "            return False\n",
    "        for i in range(9):\n",
    "            for j in range(i+1,9):\n",
    "                if s[i]=='0' or s[i]==s[j]:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = \"\"\n",
    "        m = {'1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1}\n",
    "        s = str(n) + str(n * 2) + str(n * 3)\n",
    "        for i in s:\n",
    "            if i in m and m[i] > 0:\n",
    "                m[i] = m[i] - 1\n",
    "                continue\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return ''.join(sorted(str(n) + str(2 * n) + str(3 * n))) == \"123456789\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        lst = [192, 219, 273, 327]\n",
    "        return n in lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        s = str(n) + str(2*n) + str(3*n)\n",
    "        save = set()\n",
    "        for i in s:\n",
    "            if i == '0' or i in save:\n",
    "                return False\n",
    "            save.add(i)\n",
    "        return len(save) == 9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        x = [0 for i in range(9)]\n",
    "        n2 = 2 * n\n",
    "        n3 = 3 * n\n",
    "        strle = str(n) + str(n2) + str(n3)\n",
    "        for i in strle:\n",
    "            if int(i) == 0:\n",
    "                return False\n",
    "            x[int(i)-1] += 1\n",
    "        for i in x:\n",
    "            if i - 1 != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in (192, 219, 273, 327)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        num1 = str(n)\n",
    "        num2 = str(2*n)\n",
    "        num3 = str(3*n)\n",
    "        num = num1+num2+num3\n",
    "        cnt = collections.Counter(num)\n",
    "        return len(cnt)==9 and '0' not in num and sum(cnt.values())==9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return ''.join(sorted(str(n)+str(2*n)+str(3*n)))=='123456789'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFascinating(self, n: int) -> bool:\n",
    "        return n in [192, 219, 273, 327]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
